package com.sky.controller.admin;

import com.sky.Entity.Category;
import com.sky.dto.AddCategoryDTO;
import com.sky.dto.CategoryQueryDTO;
import com.sky.dto.UpdateCategoryDTO;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "分类相关操作")
@RequestMapping("/admin/category")
@RestController()
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    @ApiOperation("新增分类接口")
    public Result<String> insert(@RequestBody AddCategoryDTO categoryDTO){
        categoryService.insert(categoryDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("分页查询分类信息")
    public Result<PageVo<Category>> pageQuery(CategoryQueryDTO categoryQueryDTO){
        PageVo<Category> pageVo = categoryService.pageQuery(categoryQueryDTO);
        return Result.success(pageVo);
    }
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类信息")
    public Result<List<Category>> pageQuery(Integer type){
        List<Category> pageVo = categoryService.pageQuery(type);
        return Result.success(pageVo);
    }
    @PutMapping
    @ApiOperation("修改分类信息")
    public Result<String> update(@RequestBody UpdateCategoryDTO updateCategoryDTO){
        categoryService.update(updateCategoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用")
    public Result<String> updateStatus(Long id,@PathVariable Integer status){
        categoryService.updateStatus(id,status);
        return Result.success();
    }
    @DeleteMapping()
    @ApiOperation("删除分类")
    public Result<String> delete(@RequestParam(required = true) Long id){
        categoryService.delete(id);
        return Result.success();
    }
}
